<%@page contentType="text/html" pageEncoding="UTF-8" import="java.io.*, java.sql.*, javax.sql.*"%>
<%

    Connection con = null;
    PreparedStatement st = null;
    try {
        con = com.elookinto.wordlist.Util.getCon();
        String uid = request.getParameter("uid");
        if (uid == null) {
            uid = (String) session.getAttribute("uid");
        }
        if (uid == null) {
            uid = request.getRemoteHost();
        }
        session.setAttribute("uid", uid);

        //String uid = (String) session.getAttribute("uid");    
        String url = request.getParameter("url");
        String desc = request.getParameter("desc");
        String title = request.getParameter("title");
        String id = java.util.UUID.randomUUID().toString();
        out.println(id);
        //if (true) return;
        st = con.prepareStatement("INSERT INTO recording  ( uid, url, desc, title, id, insert_time ) values (?, ?, ?, ?, ?, current_timestamp) ");
        st.setString(1, uid);
        st.setString(2, url);
        st.setString(3, desc);
        st.setString(4, title);
        st.setString(5, id);
        st.executeUpdate();
        String tags = request.getParameter("tag");
        if (tags != null) {
            con.setAutoCommit(false);
            String tag[] = tags.split("\\W");
             st = con.prepareStatement("INSERT INTO tag  ( id, tag) values (?, ?) ");
            for (String s: tag)
            {
                
                 st.setString(1,id);
                 st.setString(2, s);
                 st.addBatch();
            }
            st.executeBatch();
            con.commit();
            con.setAutoCommit(true);
        }

    } catch (Exception e) {
        //st.close();
        e.printStackTrace();
        con.close();
    }
%>

